草庐IT

Node.js 路由

全部标签

ruby-on-rails - 为 Rails 3.1 中的特定路由强制使用 SSL

我需要在应用程序中的所有路由上强制使用SSL,landing#index除外。在config/application.rb中,我有:config.force_ssl=true然后在landing_controller.rb中,我有:force_ssl:except=>:index但是,所有路由仍在重定向到https。有谁知道如何在Rails3.1+应用程序中有条件地强制使用SSL?解决方案:将以下内容添加到您的Gemfile:gem'rack-ssl-enforcer'将以下内容添加到您的config/application.rb:config.middleware.useRack::

ruby - 类内的路由处理程序

我有一个Sinatra应用程序设置,其中大部分逻辑在各种类中执行,post/get路由实例化这些类并调用它们的方法。我在考虑将post/get路由处理程序放在类本身中是否会是一个更好的结构。无论如何,我想知道这是否可能。例如:classExampledefsay_hello"Hello"endget'/hello'do@message=say_helloendend如果不修改以上内容,Sinatra会说SinatraApplication对象上没有方法say_hello。 最佳答案 你只需要继承Sinatra::Base:requi

ruby-on-rails - 如何在没有 CRUD 操作的情况下路由 Controller ?

我有一个包含许多操作的Controller:classTestsController当我像这样将它添加到我的routes.rb文件中时:resources:tests并执行rakeroutes任务我看到以下额外回合:testsGET/tests(.:format)tests#indexPOST/tests(.:format)tests#createnew_testGET/tests/new(.:format)tests#newedit_testGET/tests/:id/edit(.:format)tests#edittestGET/tests/:id(.:format)tests#s

ruby - 我怎样才能给 Sinatra 一个包罗万象的默认路由?

对于小型开发人员文档应用,我想设置一个Sinatra应用来仅提供HAML文件。在CSS文件和图像的路由之后,我想要一个尝试为您请求的任何路径加载HAML文件的路由。例如:/index加载views/index.haml,如果它存在的话/this/page/might/exist加载views/this/page/might/exist.haml,如果存在的话我将如何指定这条路线? 最佳答案 看起来像这样做:get'/*'doviewname=params[:splat].first#eg"some/path/here"ifFile.

ruby-on-rails - 我可以在 render.js 上执行的 View 中使用 CoffeeScript 吗?

我需要做什么才能在RailsJSView中使用CoffeeScript?例如:defindexformat.js{render:layout=>false}end我需要做什么才能让Rails使用index.js.coffee? 最佳答案 Johnny的回答是正确的。如果您查看pullrequest链接到CoffeeBeans页面,你有dhh说Oncewehaveafast,cleanimplementation,it'swelcomeincore.3.2isamorelikelytarget,though.我在Railsconf上与

ruby-on-rails - Rails 中的匹配和路由

我生成了一个Controller并更改了路由,但打开链接会在我的本地服务器上产生错误。生成Controller和路由railsgeneratecontrollerStaticPageshomeaboutteamcontact改变路线.rbMyApp::Application.routes.drawdorootto:'static_pages#home'match'/about',to:'static_pages#about'match'/team',to:'static_pages#team'match'/contact',to:'static_pages#contact'end根路径

ruby-on-rails - 没有路由匹配... Rails 引擎

所以我不断收到错误:没有路由匹配{:action=>"create",:controller=>"xaaron/api_keys"}测试中抛出的是:it"shouldnotcreateanapikeyforthosenotloggedin"dopost:createexpect(response).toredirect_toxaaron.login_pathend当我转到spec/dummy并运行rakeroutes命令时,我看到:api_keysGET/api_keys(.:format)xaaron/api_keys#indexPOST/api_keys(.:format)xaar

ruby-on-rails - 如何使用 rspec 测试命名路由?

鉴于我有一条命名路线:map.some_route'/some_routes/:id',:controller=>'some',:action=>'other'如何使用路由规范文件“spec/routing/some_routing_spec.rb”来测试该命名路由?我在“describeSomeRouteController”block之后尝试过这个,但它不起作用,我得到“未定义的方法”helper:describeSomeRouteHelper,'someroutesnamedroutes'doit'shouldrecognizesome_route'dohelper.some_r

ruby - Sinatra (Ruby) 中的静态页面路由

您可以通过将静态文件放在public/中(默认情况下)来使用Sinatra提供静态文件——目前我有一个index.html,但是如何我可以将根指向该文件而不必将其作为模板进行解析吗?明确地说,我可以成功访问/index.html,并且我想将/路由到同一个静态文件,但不重定向。知道如何做到这一点吗? 最佳答案 可能最终会出现更好的答案,在此之前这是我的尝试。如果这不是你想要的:get'/'doredirect'/index.html'end你可能会这样做:get'/'doFile.new('public/index.html').re

ruby-on-rails - Rails 3 的动态路由

我的任务是按照路由模型开发一个Rails应用程序。我需要有PageController和Page模型。页面url必须类似于/contacts、/shipping、/some_page。我还需要有CatalogController和Category模型。类别url必须类似于/laptops、/smartphones/android。它将是ProductsController和Product模型,产品的url必须是行/laptops/toshiba_sattelite_l605,/smartphones/安卓/htc_magic我知道这个问题可以通过使用像这样的URL来解决/page/sh